﻿using IMark.DAO;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IMark
{
    public partial class SanPhamKhuyenMai : System.Web.UI.Page
    {
        public string ltSanPham = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                List<SAN_PHAM> ltSanPhamKM = SanPhamModels.LaySanPhamKhuyenMai();

                ListView1.DataSource = ltSanPhamKM;
                ListView1.DataBind();
            }
        }

        protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            Label Rating = e.Item.FindControl("rating") as Label;
            Label LuotXem = e.Item.FindControl("LuotXem") as Label;
            SAN_PHAM h = e.Item.DataItem as SAN_PHAM;
            Rating.Text = Utils.GenerateRation(h.DANH_GIA.ToList());
            LuotXem.Text = h.DANH_GIA.Count().ToString();
            Image Image = e.Item.FindControl("SpecIcon") as Image;
            Image.ImageUrl = "images/products/" + h.HINH_SAN_PHAM.First().Hinh;
        }
    }
}